package com.tourismhengyang.actions;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.tourismhengyang.beans.Hotel;
import com.tourismhengyang.biz.IHotelBiz;
import com.tourismhengyang.impl.HotelBizImpl;
import com.tourismhengyang.utils.JsonObject;

public class HotelAction extends ActionSupport implements ModelDriven<Hotel>{

	private static final long serialVersionUID = 1L;
	private IHotelBiz hotelBiz=new HotelBizImpl();
	private JsonObject json;
	private Hotel hotel;
	
	public String getHotelList(){
		List<Hotel> list=hotelBiz.getHotelList();
		if(list!=null){
			json=new JsonObject();
			json.setRows(list);
			return SUCCESS;
		}
		return null;
	}
	
	public String addHotelInfo(){
		int result=hotelBiz.addHotelInfo(hotel);
		json=new JsonObject();
		json.setObj(result);
		return SUCCESS;
	}
	
	public String updateHotelInfo(){
		System.out.println(hotel);
		int result=hotelBiz.updateHotelInfo(hotel);
		json=new JsonObject();
		json.setObj(result);
		return SUCCESS;
	}
	
	public String getOneHotelInfo(){
		Hotel oneHotel=hotelBiz.getOneHotelInfo(hotel.getHid());
		json=new JsonObject();
		json.setObj(oneHotel);
		return SUCCESS;
	}
	
	public String getOneHotel(){
		List<Hotel> list=hotelBiz.getOneHotel(hotel.getLid());
		if(list!=null){
			json=new JsonObject();
			json.setRows(list);
			return SUCCESS;
		}
		return null;
	}
	
	public JsonObject getJson() {
		return json;
	}

	@Override
	public Hotel getModel() {
		if(hotel==null){
			hotel=new Hotel();
		}
		return hotel;
	}
}
